package com.workflow.workflowproject.controller;

import com.workflow.workflowproject.entity.FlowForm;
import com.workflow.workflowproject.entity.dto.TaskDataDto;
import com.workflow.workflowproject.entity.dto.TaskInfoDto;
import com.workflow.workflowproject.service.TaskService;
import com.workflow.workflowproject.tools.Result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "任务管理")
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;
    /**
     * 获取节点操作
     *
     * @param
     * @return
     */
    @PostMapping("/getOption")
    @Operation(summary="获取节点操作",description="获取节点操作")
    public Result getOption(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.getOption(taskInfo);
    }

    /**
     * 获取节点字段操作
     *
     * @param
     * @return
     */
    @PostMapping("/getFieldByNode")
    @Operation(summary="获取节点字段操作",description="获取节点字段操作")
    public Result getFieldByNode(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.getFieldByNode(taskInfo);
    }

    /**
     * 发起申请
     *
     * @param
     * @return
     */
    @PostMapping(value = "taskApply")
    @Operation(summary="发起申请",description="发起申请")
    public Result taskApply(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.taskApply(taskInfo);
    }

    /**
     * 数据暂存
     *
     * @param
     * @return
     */
    @PostMapping(value = "saveData")
    @Operation(summary="数据暂存",description="数据暂存")
    public Result saveData(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.saveData(taskInfo);
    }

    /**
     * 申请撤销
     *
     * @param
     * @return
     */
    @PostMapping(value = "revokeTask")
    @Operation(summary="申请撤销",description="申请撤销")
    public Result revokeTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.revokeTask(taskInfo);
    }

    /**
     * 申请通过
     *
     * @param
     * @return
     */
    @PostMapping(value = "passTask")
    @Operation(summary="申请通过",description="申请通过")
    public Result passTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.passTask(taskInfo);
    }

    /**
     * 申请驳回
     *
     * @param
     * @return
     */
    @PostMapping(value = "rejectTask")
    @Operation(summary="申请驳回",description="申请驳回")
    public Result rejectTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.rejectTask(taskInfo);
    }

    /**
     * 申请回退
     *
     * @param
     * @return
     */
    @PostMapping(value = "returnTask")
    @Operation(summary="申请退回",description="申请退回")
    public Result returnTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.returnTask(taskInfo);
    }

    /**
     * 流程转交
     *
     * @param
     * @return
     */
    @PostMapping(value = "passOnTask")
    @Operation(summary="流程转交",description="流程转交")
    public Result passOnTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.returnTask(taskInfo);
    }

    /**
     * 流程委派
     *
     * @param
     * @return
     */
    @PostMapping(value = "delegateTask")
    @Operation(summary="流程委派",description="流程委派")
    public Result delegateTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.delegateTask(taskInfo);
    }

    /**
     * 委派处理
     *
     * @param
     * @return
     */
    @PostMapping(value = "delegatePassTask")
    @Operation(summary="委派处理",description="委派处理")
    public Result delegatePassTask(@RequestBody TaskInfoDto taskInfo) throws Exception{
        return taskService.delegatePassTask(taskInfo);
    }

    /**
     * 通过业务ID获取数据
     *
     * @param
     * @return
     */
    @GetMapping("/taskData/{busKey}")
    @Operation(summary="通过业务ID获取数据",description="通过业务ID获取数据")
    public Result getTaskData(@PathVariable String busKey) throws Exception{
        return taskService.getTaskData(busKey);
    }

    /**
     * 获取创建任务
     *
     * @param
     * @return
     */
    @PostMapping("/getTaskByCreateUser")
    @Operation(summary="获取创建任务",description="获取创建任务")
    public Result getTaskByCreateUser(@RequestBody TaskDataDto taskDataDto) throws Exception{
        return taskService.getTaskByCreateUser(taskDataDto);
    }
    /**
     * 获取待审批任务
     *
     * @param
     * @return
     */
    @PostMapping("/getTaskByAssigner")
    @Operation(summary="获取待审批任务",description="获取待审批任务")
    public Result getTaskByAssigner(@RequestBody TaskDataDto taskDataDto) throws Exception{
        return taskService.getTaskByAssigner(taskDataDto);
    }
    /**
     * 获取审批历史
     *
     * @param
     * @return
     */
    @PostMapping("/getHistoryTask")
    @Operation(summary="获取审批历史",description="获取审批历史")
    public Result getHistoryTask(@RequestBody TaskDataDto taskDataDto) throws Exception{
        return taskService.getHistoryTask(taskDataDto);
    }
}
